Add parameter configurations on the existing hardware platform based on the schematic:
The eMMC is directly soldered onto the core board and connected to SD1 on the PS side. The TF card on the development board is connected to SD0 on the PS side.
Schematic:
Configuration Interface: Note that the TF card corresponding to SD0 uses the Card Detect pin, which corresponds to MIO9.
After synthesis and implementation, export the new .xsa file.
In Vitis, update the platform project: Right-click the created platform project, click "Update Hardware Specification," select the .xsa file path. The following pop-up box will appear; click OK, which indicates a successful update.
Because the application project needs to use a file system, you need to modify the BSP and add the file system-related package (xilffs):
Rebuild the platform project.
Next, create a new empty .c application project and add a .c file.
Add the corresponding code.
The application project code supports testing both the TF card and eMMC.
The test code is as follows:
x
const char *sd_path[] = {"0:/", "1:/"};const char *file_name[] = {"0:/test.txt", "1:/test.txt"};
const char src_str[30] = "this is a test string!";
//Initialize file systemint platform_init_fs(uint8_t sd_id){ FRESULT status;
BYTE work[FF_MAX_SS];
status = f_mount (&fatfs, sd_path[sd_id], 1 ); if (status != FR_OK) { xil_printf("Volume is not FAT formated; formating FAT\r\n");
status = f_mkfs(sd_path[sd_id], FM_FAT32, 0, work, sizeof work); if (status != FR_OK) { xil_printf("Unable to format FATfs\r\n"); return -1; }
status = f_mount(&fatfs, SD_PATH, 1); if (status != FR_OK) { xil_printf("Unable to mount FATfs\r\n" ); return -1; } } return 0;}
//Mount SD (TF) cardint sd_mount(uint8_t sd_id){ FRESULT status;
status = platform_init_fs(sd_id); if (status) { xil_printf("ERROR: f_mount returned %d!\n", status); return XST_FAILURE; } return XST_SUCCESS;}
//SD card write dataint sd_write_data(char *file_name, u32 src_addr, u32 byte_len){ FIL fil; UINT bw;
f_open(&fil, file_name, FA_CREATE_ALWAYS | FA_WRITE); f_lseek(&fil, 0); f_write(&fil, (void *)src_addr, byte_len, &bw); f_close(&fil); return 0;}
//SD card Read dataint sd_read_data(char *file_name, u32 src_addr, u32 byte_len){ FIL fil; UINT br;
f_open(&fil, file_name, FA_READ); f_lseek(&fil, 0); f_read(&fil, (void *)src_addr, byte_len, &br); f_close(&fil); return 0;}
void sd_emmc_test(uint8_t sd_id){ int status, len; char dest_str[30] = "";
status = sd_mount(sd_id); if(status != XST_SUCCESS ) { xil_printf("Failed to open SD card!\r\n" ); return 0; } else xil_printf("Success to open SD card!\r\n");
len = strlen(src_str ); sd_write_data(file_name[sd_id],(u32)src_str, len ); sd_read_data(file_name[sd_id],(u32)dest_str, len );
if (strcmp(src_str, dest_str) == 0) { xil_printf("src_str is equal to dest_str, SD card test success!\r\n"); } else { xil_printf("src_str is not equal to dest_str, SD card test failed!\r\n"); }}
Follow the compilation and debugging steps in the IIC documentation.
Before testing the TF card, insert the TF card first.
Connect the JTAG USB cable and the PS UART cable, then power the development board.
In Vitis, enter debug mode, download the program, and execute it. Debugging results: